package com.boot.message.rabbit;

import cn.hutool.core.util.IdUtil;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;

/**
 * @author 霜寒 <1621856595@qq.com>
 * @description RabbitMQ生产者
 * @date 2020/4/30 1:17
 **/
@Service
public class RabbitMQSender {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void sendToGroup(Object message) throws IOException {
        CorrelationData correlationData = new CorrelationData(IdUtil.fastSimpleUUID());
        rabbitTemplate.convertAndSend("bootExchange", "group", message, correlationData);
    }

    public void sendToUser(Object message) throws IOException {
        CorrelationData correlationData = new CorrelationData(IdUtil.fastSimpleUUID());
        rabbitTemplate.convertAndSend("bootExchange", "user", message, correlationData);
    }

}
